package com.ruoyi.household.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.household.domain.Household;
import com.ruoyi.household.dto.HouseholdDto;
import com.ruoyi.household.service.IHouseholdService;
import org.apache.catalina.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 住户管理CRUDController
 * 
 * @author ruoyi
 * @date 2022-10-01
 */
@RestController
@RequestMapping("/household")
public class HouseholdController extends BaseController
{
    @Autowired
    private IHouseholdService householdService;

    @GetMapping(value = "/user/{getUserId}")
    public Household getUser(@PathVariable("getUserId") Long id)
    {
        Household user = householdService.getUser(id);
        System.out.println(user);
        return user;
    }


    /**
     * 根据住户名字查询
     */
    @GetMapping(value = "/getHouseholdName/{householdName}")
    public Household getHouseholdName(@PathVariable("householdName") String householdName)
    {

        return householdService.getHouseholdName(householdName);
    }

    /**
     * 根据小区名字查询
     */
    @GetMapping(value = "/getHousehold/{HouseholdName}")
    public List<Household> getHousehold(@PathVariable("HouseholdName") String name)
    {

        return householdService.getHousehold(name);
    }

    /**
     * 查询住户管理CRUD列表
     */
    @RequiresPermissions("household:household:list")
    @GetMapping("/list")
    public TableDataInfo list(Household household)
    {
        startPage();
        List<Household> list = householdService.selectHouseholdList(household);
        return getDataTable(list);
    }

    /**
     * 导出住户管理CRUD列表
     */
    @RequiresPermissions("household:household:export")
    @Log(title = "住户管理CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Household household)
    {
        List<Household> list = householdService.selectHouseholdList(household);
        ExcelUtil<Household> util = new ExcelUtil<Household>(Household.class);
        util.exportExcel(response, list, "住户管理CRUD数据");
    }

    /**
     * 获取住户管理CRUD详细信息
     */
    @RequiresPermissions("household:household:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(householdService.selectHouseholdById(id));
    }

    /**
     * 新增住户管理CRUD
     */
    @RequiresPermissions("household:household:add")
    @Log(title = "住户管理CRUD", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseholdDto dto)
    {
        return toAjax(householdService.insertHousehold(dto));
    }

    /**
     * 修改住户管理CRUD
     */
    @RequiresPermissions("household:household:edit")
    @Log(title = "住户管理CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Household household)
    {
        return toAjax(householdService.updateHousehold(household));
    }

    /**
     * 删除住户管理CRUD
     */
    @RequiresPermissions("household:household:remove")
    @Log(title = "住户管理CRUD", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(householdService.deleteHouseholdByIds(ids));
    }

}
